package com.central.product.service.serviceImp

import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.central.common.entity.DrawCategory
import com.central.common.model.CommonResult
import com.central.common.model.PageVo
import com.central.common.model.failed
import com.central.common.model.success
import com.central.common.service.impl.SuperServiceImpl
import com.central.product.mapper.DrawCategoryMapper
import com.central.product.service.DrawCategoryService
import org.springframework.stereotype.Service

/**
 * @author  fly
 * @date  2021/5/26 14:53
 * @version 1.0
 */
@Service
open class DrawCategoryServiceImp : SuperServiceImpl<DrawCategoryMapper, DrawCategory>(), DrawCategoryService {


    override fun get(id: Long): CommonResult<DrawCategory> = success(
        getById(id)
    , "获取成功")

    override fun getAll(): CommonResult<List<DrawCategory>> = success(
        list()
   , "获取成功" )

    override fun getByPage(pageVo: PageVo): CommonResult<Page<DrawCategory>> = success(
        page(Page(pageVo.pageNumber!!, pageVo.pageSize!!))
    , "获取成功")

    override fun saveOrUpdateDrawCategory(drawCategory: DrawCategory): CommonResult<DrawCategory> =
        saveOrUpdate(drawCategory).takeIf { it }?.run { success(drawCategory, "添加成功")}
            ?: failed("添加失败")

    override fun delAllByIds(ids: Array<String>): CommonResult<Any> = success(
        ids.forEach { removeById(it) }
    , "批量通过id删除数据成功")


}
